﻿@using Kaqaz.Common.Security
@using Xoqal.Security
@using Xoqal.Data.Models
@model Paginated<Kaqaz.Models.Post>

@{
    ViewBag.Title = "Blog";
}

@if (Authentication.Default.IsUserInPermission(Permissions.PostManagement))
{
<p class="post-command">    
    @Html.ActionLink(Resource.NewPost, "Create", null, new { @class = "post-create link-button" })
</p>
}

@foreach (var item in Model.Data) {
    <div class="post">
        @if (Authentication.Default.IsUserInPermission(Permissions.PostManagement))
        {
            <div class="post-detail-commands">
            <a href="@Url.Action("Edit", new { id = item.Id })">
                <img src="@Url.Content("~/Content/Images/Icons/Edit.png")" alt="@Resource.Edit" />
            </a>
            <a href="@Url.Action("Delete", new { id = item.Id })" onclick="return confirm('@Resource.DeleteConfirmMessage')">
                <img src="@Url.Content("~/Content/Images/Icons/Delete.png")" alt="@Resource.Delete" />
            </a>
            </div>
        }
        <div class="post-header">
            <div class="post-time">
                @(item.CreateTime.HasValue ? GlobalDateTime.ToLongDateString(item.CreateTime.Value) : string.Empty)
            </div>
            <div class="post-title">
                @Html.ActionLink(item.Title, "Details", new { id = item.Id })
            </div>
        </div>

        <div class="post-summary-main">
            @Html.Raw(item.Summary)
        </div>
        
        @if (item.LastUpdateTime != null)
        {
        <div class="post-lastupdate">
            @Resource.LastUpdateTime: @GlobalDateTime.ToLongDateString(item.LastUpdateTime.Value)
        </div>
        }

        <div class="post-detail-footer @((item.IsCommentsEnable || item.Tags.Count() != 0) ? "post-detail-footer-withcontent" : string.Empty)">
            @if (item.IsCommentsEnable)
            {
            <span class="post-comments">
                @Html.ActionLink(string.Format("{0} [{1}]", Resource.Comment, item.VisibleComments.Count()), "Details", new { id = item.Id, sc = 1 })
            </span>
            }
        
            @if (item.Tags.Count() != 0)
            {
                if (item.IsCommentsEnable)
                { 
                    <text>|</text>
                }
            
                @Html.Partial("Tags", item.Tags)
            }
        </div>
    </div>
}

<div class="blog-postspaging">
@if (ViewBag.NextPageIndex != null)
{
    @Html.RouteLink(Resource.PrevPosts, new { page = ViewBag.NextPageIndex }, new { @class = "link-paging-prev" })
}
@if (ViewBag.PrevPageIndex != null)
{
    @Html.RouteLink(Resource.NextPosts, new { page = ViewBag.PrevPageIndex }, new { @class = "link-paging-next" })
}
</div>